#include "LastPosition.h"
#include <sstream>
#include <QtGui/QFrame>

LastPosition::LastPosition(RobotMap* map)
{
	_map = map ;
	_current.first = _current.second = -1 ;
	_last.first = _last.second = -1 ;
	
	_statusPanel = new QFrame() ;
	_statusPanel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
// 	_statusPanel->setLineWidth(2);
	_pos = new QLabel(_statusPanel) ;
	_pos->move(5,5);
	updateDatas() ;
}

LastPosition::~LastPosition()
{
	delete _statusPanel ;
}

int LastPosition::firstValue()
{
	return _last.first ;
}

int LastPosition::secondValue()
{
	return _last.second ;
}

void LastPosition::updateDatas()
{
	_last.first = _current.first ;
	_last.second = _current.second ;
	_current.first = _map->position().first ;
	_current.second = _map->position().second ;
	
	std::ostringstream oss;
	std::string truc = "Derniere position : " ;
	oss << firstValue() ;
	truc += oss.str() + " : " ;
	oss.str("") ;
	oss << secondValue() ;
	truc += oss.str() ;
	_pos->setText(QString(truc.c_str()));
	
	_pos->adjustSize();
}